import Notification from './notification.vue';
import { Noticeinfo } from "./noticeConfig"
import Vue, { CreateElement } from 'vue';
export function newInstance(properties: object) {
  const _props = properties || {};

  const Instance = new Vue({
    render(h: CreateElement) {
      return h(Notification, {
        props: _props
      });
    }
  });

  const component = Instance.$mount();
  document.body.appendChild(component.$el);
  const notification = Instance.$children[0];

  return {
    component: notification,
    createNotice(noticeProps: Noticeinfo) {
      (notification as any).add(noticeProps);
    },
    removeNotice(name: string) {
      (notification as any).close(name);
    },
    destroy(element: string) {
      (notification as any).closeAll();
      setTimeout(function () {
        document.body.removeChild(document.getElementsByClassName(element)[0]);
      }, 500);
    }
  };
}